package bancosys.tec.security.impl.services.incluir;

import jmine.tec.di.annotation.Injected;
import jmine.tec.services.annotations.Execution;
import jmine.tec.services.annotations.Input;
import jmine.tec.services.annotations.ServiceImplementor;
import jmine.tec.services.api.ActionsEnum;
import bancosys.tec.persist.dao.BaseDAO;
import bancosys.tec.security.impl.domain.ChineseWallCredential;
import bancosys.tec.security.impl.domain.ChineseWallEntityId;

/**
 * Serviço para relacionar um id da entidade a credencial de ChineseWall
 * 
 * @author rodrigok
 */
@ServiceImplementor(action = ActionsEnum.INCLUIR)
public class ChineseWallEntityIdService {

    public static final String CREDENTIAL = "Credencial";

    public static final String ENTITY_ID = "Id da Entidade";

    // Injected
    private BaseDAO<ChineseWallEntityId> dao;

    // Obrigatórios
    private ChineseWallCredential credential;

    private Long entityId;

    /**
     * Executa a geração do relacionamento do id da entidade ao chinese wall.
     */
    @Execution
    public void execute() {
        ChineseWallEntityId cwEntityId = this.dao.createBean();
        cwEntityId.setCredential(this.credential);
        cwEntityId.setEntityId(this.entityId);
        cwEntityId.getPersister().save();
    }

    /**
     * @param dao ChineseWallEntityIdDAO.
     */
    @Injected
    public void setDao(BaseDAO<ChineseWallEntityId> dao) {
        this.dao = dao;
    }

    /**
     * @param credential {@link ChineseWallCredential}
     */
    @Input(fieldName = CREDENTIAL)
    public void setCredential(ChineseWallCredential credential) {
        this.credential = credential;
    }

    /**
     * @param entityId Id da entidade
     */
    @Input(fieldName = ENTITY_ID)
    public void setEntityId(Long entityId) {
        this.entityId = entityId;
    }

}
